import 'package:cook_dinner/pages/order/order_view/order_item.dart';
import 'package:cook_dinner/widgets/custom_appbar.dart';
import 'package:flutter/material.dart';
import 'package:cook_dinner/config/include.dart';

const List<String> tabText = ['全部', '待付款', '待发货', '待收货', '已完成'];
const List<String> tabState = ['已收货', '等待买家付款', '待发货', '待收货', '已完成'];

class OrderList extends StatefulWidget {
  const OrderList({Key? key}) : super(key: key);

  @override
  State<OrderList> createState() => _OrderListState();
}

class _OrderListState extends State<OrderList> with TickerProviderStateMixin {
  late TabController _tabController;
  int _current = 0;

  @override
  void initState() {
    _tabController = TabController(length: tabText.length, vsync: this)
      ..addListener(() {
        _current = _tabController.index;
        setState(() {});
      });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: tabText.length,
      child: Scaffold(
        backgroundColor: const Color(0xfff9f9f9),
        appBar: AppBarCustom(
          '我的订单',
          height: 80.rpx + HYSizeFit.statusHeight,
          bottom: PreferredSize(
            preferredSize: Size.fromHeight(50.rpx),
            child: Container(
              height: 50.rpx,
              width: double.infinity,
              padding: EdgeInsets.only(left: 5.rpx),
              child: TabBar(
                controller: _tabController,
                tabs: List.generate(
                  tabText.length,
                  (index) => Tab(text: tabText[index]),
                ),
                isScrollable: true,
                padding: EdgeInsets.only(
                    left: 0, right: 0, bottom: 0.rpx, top: 0.rpx),
                labelPadding: EdgeInsets.symmetric(horizontal: 20.rpx),
                indicatorPadding: EdgeInsets.only(bottom: 10.rpx),
                labelColor: const Color(0xffFA8303),
                labelStyle: TextStyle(fontSize: 16.rpx),
                unselectedLabelColor: const Color(0xff19140E),
                unselectedLabelStyle: TextStyle(fontSize: 16.rpx),
                indicatorSize: TabBarIndicatorSize.label,
                indicatorColor: const Color(0xffFA8303),
              ),
            ),
          ),
        ),
        body: ListView.builder(
          padding: EdgeInsets.only(top: 37.rpx, left: 21.rpx, right: 21.rpx),
          itemCount: 5,
          itemBuilder: (context, index) {
            return OrderItem(
              text: tabState[_current],
              tab: _current,
            );
          },
        ),
      ),
    );
  }
}
